#include "Logger.h"
#include "Timestamp.h"

#include <iostream>

// 获取唯一的日志示例对象
Logger& Logger::getInstance()
{
    static Logger logger;
    return logger;
}

// 设置日志的级别
void Logger::setLogLevel(LogLevel level)
{
    m_logLevel = level;
}

// 获取日志级别
LogLevel Logger::getLogLevel() const
{
    return m_logLevel;
}

// 写日志 [级别信息] time filename::function::line : msg
void Logger::log(std::string msg)
{
    LogLevel level = Logger::getInstance().getLogLevel();
    switch (level)
    {
    case LogLevel::INFO:
        std::cout << "[INFO]";
        break;
    
    case LogLevel::ERROR:
        std::cout << "[ERROR]";
        break;

    case LogLevel::FATAL:
        std::cout << "[FATAL]";
        break;

    case LogLevel::DEBUG:
        std::cout << "[DEBUG]";
        break;    

    default:
        break;
    }

    // 打印时间和对应的msg  time filename::function::line : msg
    std::cout << Timestamp::now().toString() << " " << __FILE__ << "::" << __FUNCTION__ << "::" 
                              << __LINE__ << " : " << msg << std::endl;
}
